package com.cmwa.scbp.base.config.encryption;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;

/*@Configuration*/
public class Encryptor {
	
	/*
	 * 如果数据库加密解密密钥放在application.properties中，那此处无需提供此类。若在配置文件无配置，则可放开此处注释，提供解密类
	 */
	
	
	/*@Bean("jasyptStringEncryptor")*/
    public StringEncryptor stringEncryptor() {
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        config.setPassword("key4encrootstring");
        config.setAlgorithm("PBEWithMD5AndDES");
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setStringOutputType("base64");
        encryptor.setConfig(config);
        return encryptor;
    }
    
    public static void main(String[] args) {
    	Encryptor encryptor = new Encryptor();
    	System.out.println(encryptor.stringEncryptor().decrypt("LLulb3PkxYIycXvT4c7egWC5W7/n9DWg"));
    	System.out.println(encryptor.stringEncryptor().encrypt("cmf+2011"));
	}
}
